package com.huluobo.a2210monthdemo.views

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.huluobo.a2210monthdemo.R
import com.huluobo.lib_base.RoutePath

/**
 *  Created by LC on 2025/4/10.
 */
sealed class NavItem(val route: String, val title: String, val img: Int) {
    data object MessagePage : NavItem(RoutePath.MESSAGE, "消息", R.drawable.message)
    data object HomePage : NavItem(RoutePath.HOME, "门户", R.drawable.home)
    data object MinePage : NavItem(RoutePath.MINE, "我的", R.drawable.home)
}

@Composable
fun MainPage() {
    val list = listOf(NavItem.MessagePage, NavItem.HomePage, NavItem.MinePage)
    val navHostController = rememberNavController()

    val stackEntryState by navHostController.currentBackStackEntryAsState()
    val destination = stackEntryState?.destination

    Scaffold(
        bottomBar = {
            if (destination?.hierarchy?.any {
                    list.map { navItem ->
                        navItem.route
                    }.contains(it.route)
                } == true)
                NavigationBar {
                    list.forEach {
                        NavigationBarItem(selected = false, onClick = {
                            navHostController.navigate(it.route)
                        }, icon = {
                            Image(painter = painterResource(id = it.img), contentDescription = "")
                        }, label = {
                            Text(text = it.title)
                        })
                    }
                }
        }
    ) {
        MyNavHost(it = it, navHostController = navHostController)
    }
}